Secure execution of a computer program

ABSTRACT

Hijacking of an application is prevented by monitoring control flow transfers during program execution in order to enforce a security policy. At least three basic techniques are used. The first technique, Restricted Code Origins (RCO), can restrict execution privileges on the basis of the origins of instruction executed. This distinction can ensure that malicious code masquerading as data is never executed, thwarting a large class of security attacks. The second technique, Restricted Control Transfers (RCT), can restrict control transfers based on instruction type, source, and target. The third technique, Un-Circumventable Sandboxing (UCS), guarantees that sandboxing checks around any program operation will never be bypassed.

This application claims the benefit of provisional patent applicationSer. No. 60/435,304 filed Dec. 19, 2002; the disclosure of which isincorporated herein by reference in its entirety.

STATEMENT REGARDING FEDERALLY SPONSORED RESEARCH

This invention was made with government support under Contract No.F29601-01-2-0166 awarded by the Air Force. The government has certainrights in the invention.

CROSS REFERENCE TO RELATED APPLICATIONS

This Application is related to U.S. patent application Ser. No.10/739,499, titled “Secure Execution Of A Computer Program Using A CodeCache,” by Derek L. Bruening, Vladimir L. Kiriansky and Saman P.Amarasinghe, filed Dec. 18, 2003, the same day as the presentapplication, published as U.S. 2005/0010804 on Jan. 13, 2005, andincorporated herein by reference in its entirety.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates generally to securing computer systems.

2. Description of the Related Art

Remote exploitation of program vulnerabilities poses a very seriousthreat to modern information infrastructures. Because of the monocultureof modern computer software, a single vulnerability in a critical pieceof software can make millions of computers susceptible to attacks. Thesesusceptible computers are exploited by rapid, automatic,self-propagating programs, or worms, that gain control over a largenumber of them.

The lifecycle of a typical attack can be divided into three phases. Inthe first phase (“the enter phase”) an attack enters the computer systemby taking advantage of a vulnerability or bug such as a buffer overflowor a format string vulnerability in a privileged program. Thesevulnerabilities allow an attack to send malformed data from a remotehost that will result in an insertion of data or modification of certainmemory locations in the address space of the program. By modifying keyprogram data such as the return addresses in the stack or jump tables inthe heap, the attack moves to the next phase (“hijacking phase”) byhijacking the control from the program. After the program is hijacked,instructions carried out on behalf of the program are in fact theinstructions dictated by the attack. Now the attack enters the finalphase (“the compromise phase”) where it executes a sequence ofinstructions that compromises the computer. This can lead to selfpropagation of the worm and infection of other computers, anddestruction or disclosure of the information on the local machine.

Traditional forms of protection against these attacks have focused onstopping them in either the enter phase or the compromise phase. Inattempting to stop an attack in the enter phase, all the input stringsare scrutinized in order to identify possible attacks. Although knownexploits can be stopped using signatures, that does not stop previouslyunknown or “zero day” attacks. It is very difficult to prevent allexploits that allow address overwrites, as they are as varied as programbugs themselves. Furthermore, there are no effective techniques that canstop malevolent writes to memory containing program addresses inarbitrary programs, because addresses are stored in many differentplaces and are legitimately manipulated by the application, compiler,linker and loader.

The second traditional approach is to stop an attack in the compromisephase. These forms of policy enforcement use limited types of targetsystem events that they can monitor, such as API or system calls. SeeGolan [U.S. Pat. No. 5,974,549] or Hollander [U.S. Pat. No. 6,412,071]for examples of these. Such a coarse-grained approach cannot accuratelymonitor improper control transfers of the above type and are known toproduce many false positives.

Therefore, a need exists in the industry to address the aforementioneddeficiencies and inadequacies.

SUMMARY OF THE INVENTION

The present invention, roughly described, pertains to securing computingsystems in order to prevent security attacks that are based upon takingcontrol of a computer program.

Rather than attempting to stop an attack during the enter or thecompromise phase, one embodiment of the present invention prevents thehijack of an application—the transfer of control to malevolent code.This is achieved by monitoring control flow transfers during programexecution in order to enforce a security policy. Most modern attacksviolate a security policy, satisfied by the normal execution of theapplication, in order to hijack the application. One embodiment of thepresent invention provides at least three basic techniques as buildingblocks for security policies. The first technique, Restricted CodeOrigins (RCO), can restrict execution privileges on the basis of theorigins of the instructions. This distinction can ensure that maliciouscode masquerading as data is never executed, thwarting a large class ofsecurity attacks. The second technique, Restricted Control Transfers(RCT), can restrict control transfers based on instruction type, source,and/or target. The final technique, Un-Circumventable Sandboxing (UCS),guarantees that sandboxing checks around any program operation willnever be bypassed.

One embodiment of the present invention includes monitoring control flowtransfers for a program running on said computing system and enforcing asecurity policy on said control flow transfers. Another embodiment ofthe present invention includes monitoring control flow transfers for aprogram running on said computing system and using a code cache toenforce a security policy on said control flow transfers.

The present invention can be accomplished using hardware, software, or acombination of both hardware and software. The software used for thepresent invention is stored on one or more processor readable storagedevices including hard disk drives, CD-ROMs, DVDs, optical disks, floppydisks, tape drives, RAM, ROM, flash memory or other suitable storagedevices. In alternative embodiments, some or all of the software can bereplaced by dedicated hardware including custom integrated circuits,gate arrays, FPGAs, PLDs, and special purpose processors. In oneembodiment, software implementing the present invention is used toprogram one or more processors. The processors can be in communicationwith one or more storage devices, peripherals and/or communicationinterfaces.

These and other objects and advantages of the present invention willappear more clearly from the following description in which thepreferred embodiment of the invention has been set forth in conjunctionwith the drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of the abstract components of ProgramShepherding.

FIG. 2 is a classification table of attacks and how a system protectedby Program Shepherding is resilient to them.

FIG. 3 is a block diagram of possible application-specific policygeneration work flow.

FIG. 4 is a block diagram of analysis and instrumentation of sourcecode.

FIG. 5 is a block diagram of analysis and instrumentation in thecompiler.

FIG. 6 is a block diagram of analysis and instrumentation of the binary.

FIG. 7 is a block diagram of analysis and instrumentation at runtime.

FIG. 8 is an overview block diagram of an embodiment using a runtimeemulator.

FIG. 9 is a flow chart describing the setup process of the embodiment inFIG. 8.

FIG. 10 is a flow chart describing the operations of the embodiment inFIG. 8.

FIG. 11 is a flow chart describing the call pre-check handling of theembodiment in FIG. 8.

FIG. 12 is an overview block diagram of an embodiment using a softwarecode cache.

FIG. 13 is a flow chart describing the Monitor Processor of theembodiment in FIG. 12.

FIG. 14 is a flow chart describing the Block Builder of the embodimentin FIG. 12.

FIG. 15 is a flow chart describing the Code Cache of the embodiment inFIG. 12.

FIG. 16 is a flow chart describing the Trace Check of the embodiment inFIG. 12.

FIG. 17 is a flow chart describing the Trace Builder of the embodimentin FIG. 12.

FIG. 18 is a flow chart describing the Execution processor of theembodiment in FIG. 12.

FIG. 19 is a flow chart describing the Enforcement of Code Origins ofthe embodiment in FIG. 12.

FIG. 20 is a flow chart describing the Enforcement of Restricted ControlTransfer of the embodiment in FIG. 12.

FIG. 21 is a flow chart describing the Enforcement of Restricted ControlTransfer of Calls of the embodiment in FIG. 12.

FIG. 22 is a flow chart describing the Enforcement of Un-CircumventableSandbox Checks of the embodiment in FIG. 12.

FIG. 23 is a flow chart describing the Sandboxing Exceptions of theembodiment in FIG. 12.

FIG. 24 is a flow chart describing the Context Switch of the embodimentin FIG. 12.

FIG. 25 is a flow chart describing Restricted Control Transfer stackdiscipline enforcement rule.

FIG. 26 is a flow chart describing Restricted Control Transfer stackdiscipline enforcement rule implemented using a shadow stack in memory.

FIG. 27 is a flow chart describing Restricted Control Transfer stackdiscipline enforcement rule implemented using a shadow stack in the XMMregisters as a fixed buffer.

FIG. 28 is a flow chart further describing the shadow stack in the XMMregisters in FIG. 27.

FIG. 29 is a flow chart describing Restricted Control Transfer stackdiscipline enforcement rule implemented using a shadow stack in the XMMregisters as a shift register.

FIG. 30 is a flow chart further describing the shadow stack in the XMMregisters in FIG. 29.

FIG. 31 is a flow chart describing function analysis in order to createan application-specific Restricted Control Transfer policy.

FIG. 32 is a flow chart describing branch analysis in order to create anapplication-specific Restricted Control Transfer policy.

FIG. 33 is a flow chart describing branch instrumentation and gatheringof runtime profile information in order to create anapplication-specific Restricted Control Transfer policy.

DETAILED DESCRIPTION

The goal of most security attacks is to gain unauthorized access to acomputer system by taking control of a vulnerable program. This isgenerally done by exploiting bugs that allow overwriting stored programaddresses with pointers to malicious code. An attacker who gains controlover a program can simply inject code to perform any operation that theoverall application has permission to do. Hijacking trusted applicationsthat are typically run with global permissions, such as login servers,mail transfer agents, and web servers, gives full access to machineresources.

Many attacks hijack the target program by performing actions that thetarget program was never intended to perform. In short, they violate theexecution model followed by legitimate program runs. The execution modelencompasses the Application Binary Interface (ABI), the callingconvention and higher-level specifications from the program's sourceprogramming language. The model also incorporates components specific tothe program, for example, which values a particular function pointer maytake.

A program's execution model is invariably narrower than that imposed bythe underlying hardware, because there is typically no efficient way inhardware to require that the specific rules of this execution model beadhered to. The result is that the execution model becomes, in practice,a convention rather than a strict set of rules. If these rules wereenforced, and only program actions that the programmer intended wereallowed, a majority of current security holes would be closed and mostmodern worm attacks would have been thwarted.

One aspect of the present invention includes Program Shepherding, whichis an approach to preventing execution of malicious code by monitoringall control transfers to ensure that each control transfer satisfies agiven security policy. Program Shepherding includes at least threetechniques: Restricted Code Origins (RCO), Restricted Control Transfers(RCT), and Un-Circumventable Sandboxing (UCS).

Restricted Code Origins

In monitoring all code that is executed, each instruction's origins arechecked against a security policy to see if it should be given executeprivileges. This restriction can be used to ensure that malicious codemasquerading as data is never executed, thwarting the largest class ofcurrent security attacks.

For example, code origins can be classified into these categories:

-   -   from the original image on disk and unmodified;    -   dynamically generated but unmodified since generation; and    -   code that has been modified.        Finer distinctions, as well as other distinctions, can also be        made.

Restricted Control Transfers

Program shepherding allows arbitrary restrictions to be placed oncontrol transfers in an efficient manner. These restrictions can bebased on the source and/or destination of a transfer as well as the typeof transfer (direct or indirect call, return, jump, etc.). For example,the calling convention could be enforced by requiring that a returninstruction only target the instruction after a call. Another example isforbidding execution of shared library code except through declaredentry points. These restrictions can further prevent attackers fromforming malicious code sequences from existing code. Different policieswill obtain different suitable trade-offs between security, performanceand applicability.

Un-Circumventable Sandboxing

Sandboxing generally refers to enforcing restrictions on a specificinstruction or a sequence of instructions. This requires alwaysexecuting a pre-defined prologue before all executions of the saidinstruction and/or a pre-defined epilogue afterwards. With the abilityto monitor all transfers of control, program shepherding is able toguarantee that these sandboxing checks cannot be bypassed. Sandboxingwithout this guarantee can never provide true security—if an attack cangain control of the execution, it can jump straight to the sandboxedoperation, bypassing the checks. In addition to allowing construction ofarbitrary security policies, this guarantee is used to enforce the othertwo program shepherding techniques by protecting the shepherding systemitself.

Dependencies

Program Shepherding provides a set of interrelated components that aremutually reinforcing. This means that any successful attack on ProgramShepherding will need to solve many complex problems simultaneously.

For example, some embodiments require operating system-levelwrite-protection on code that is determined to be trusted. RCO insuresthat only such trusted code is executed. Further, by adding semanticchecks, UCS insures that such trusted execution is not subverted by themodification of page protection permissions. In turn, RCT insures thatthese inserted checks are not bypassed.

Enforceable Rules

Restricted code origins, restricted control transfers andun-circumventable sandboxing are used to enforce fundamental conventionsthat are followed by all programs, such as the application binaryinterface and the calling convention. The techniques can also be used toenforce best or safe programming practices that programs should adhereto, as well as adhering to program-specific behavior. These restrictionslead to a plethora of enforceable rules. In this section, some of thepossible rules are described. However, this list is not exhaustive; therules can be modified and other rules can also be used.

The first set of rules is on code origins. These rules dictate whichinstructions are considered valid instructions. If no active rule issatisfied for an instruction (see the Security Policy section), theinstruction is suspected of being injected by an attack.

-   1. Execute an instruction if it is from a code page of the original    application or library image on disk, where the page was unmodified    during the execution of the application. One possible implementation    of this restriction requires an unmodified page list to be    maintained.-   2. Execute an instruction if it was present when the application or    library image was originally loaded from the disk and the    instruction was never modified after load. One possible    implementation of this restriction requires write-protecting all    possible code pages after loading the application, and creating a    protected shadow copy when the application attempts to modify a data    value in a protected page. This requires maintaining several lists    including a list of protected pages and a list of partially modified    pages.-   3. A relaxation of the first and second rule where a dynamically    loaded library is considered valid, and the code pages loaded will    be treated as valid code.-   4. A simple restriction to 3 where the only valid load library call    is when the dll name is derived from the static data space.

The above rules are sufficient for most regular applications. The nextset of rules relaxes the code origins enforcement to allow dynamicallygenerated code, as practiced in runtime systems for interpretedlanguages such as Java, Visual Basic, and the Microsoft Common LanguageRuntime framework.

-   5. Execute an instruction from regions application vendors have    identified as dynamically generated code using a vendor specific    API.-   6. Execute an instruction from a page that is allocated as    executable. This is important because some architectures such as    IA-32 do not have the necessary hardware support to enforce an    execution flag even though the operating system maintains this    information.-   7. Further restrict 6 where pages allocated as executable must be    read-only.-   8. Execute an instruction from pages once marked as writable but    later marked as read-only and executable.-   9. Further restrict 8 to only when the protection change to    read-only and executable is performed by the loader or any other    authorized code region.-   10. A further restriction on 8 and 9 where pages have to be    originally allocated as executable.-   11. A further restriction to 6, 7, 8 and 9 where the system only    allows execution of instructions from pages allocated to the heap    and not the stack.-   12. Execute an instruction if that instruction was part of a region    that was explicitly flushed from the hardware instruction cache.-   13. Further restrict 12 to only allow execution of instructions that    were not modified after the flush from the hardware instruction    cache.-   14. Execute instructions of a block of code provided that the block    of code does not contain system calls or only contains a limited    subset of system calls.-   15. Allow only certain sequences of dynamically generated    instructions (for example, known trampolines) to be executed.-   16. Execute an instruction from a heap region allocated by specific    calls to memory allocation routines (for example, known allocation    points that allocate buffers for dynamic code generation).-   17. Allow execution of self modifying code.-   18. Relax 7, 8, 9, 10, 11, 12, and/or 13 to allow the execution of    modified instructions where only the immediate value of the    instruction is changed.

The next sets of rules relate to restricting control transfers. If amatching active rule is found for a given source address, destinationaddress and the type of instruction, the control transfer is consideredvalid. If no matching active rule is found, the control transfer issuspected of being instigated by an attack.

The first set describes how to restrict calls and jumps between andwithin a module. A module is defined as a unit of program code that isloaded in to the application's address space. A module can be theexecutable file, a dynamically linked library (DLL) or a singleallocation region of dynamically generated code. Each module consists ofgroups of instructions or functions. Normally each function has a singleentry point so that the other functions can invoke and execute the saidfunction by transferring control to the entry point. However, it ispossible to have multiple entry points for one function.

-   19. Allow control to be transferred between modules when the binding    is provided in an interface list. In one embodiment, an entry of the    interface list includes a source module name, source address offset    within the module, the destination module name and the destination    address offset within the module.-   20. Allow control transfer between modules when the destination    address was included in the import list of the source module. The    import list of symbols, which is normally used by the loader to    identify the external functions needed by the executable or the DLL,    is included in most common binary formats.-   21. Allow control transfer between modules when the destination    address was included in the export list of the destination module.    The export list of symbols, which is normally used by the loader to    identify what functions of the executable or the DLL can be used by    the other modules, is included in most common binary formats.-   22. A combination that satisfies both 20 and 21.-   23. Allow control transfer when the source or destination or both    are explicitly identified as a known callback. Normally a callback    is setup by passing an address of a function or an entry point to    another module so that the other module can invoke the said function    when needed.-   24. Allow call (and jump) instructions from libraries to the program    or other libraries.-   25. Allow call (and jump) instructions between modules.-   26. Allow control to be transferred when the binding is provided in    an interface list.-   27. Allow call instructions to known function entry points.-   28. Allow direct call instructions. A control transfer is direct    when the destination address is fixed or embedded within the    instruction.-   29. Allow indirect call instructions. A control transfer is indirect    when the destination address is derived or read from the data memory    or registers.-   30. Allow direct (and indirect) jump instructions which include both    conditional and unconditional jumps.-   31. Restrict 28, 29, and/or 30 to allow only these cases where both    the source and destination are within a single module.-   32. Restrict 30 to only allow those cases when both the source and    the destination are within a single function.    The next set of rules restricts return instructions.-   33. Allow returns if the return destination is preceded by a direct    call instruction.-   34. Allow returns if the return destination is preceded by an    indirect call instruction.-   35. Restrict 33 and/or 34 to allow only those cases when the source    and destination are in the same module.-   36. Allow returns if the return destination is preceded by a call    instruction that was previously executed.-   37. Allow returns if the return destination is preceded by a direct    call instruction and the return instruction is in the function    pointed to by that call.-   38. Maintain a shadow stack of return addresses and then check if    the return address indicated in the program stack matches that in    the shadow stack. Another embodiment is to store the top section of    the shadow stack in a rarely used SIMD register set, such as the XMM    registers in the IA-32 architecture.-   39. Enforce the stack discipline using a single hash value that is    occasionally stored and later checked to ensure that the intervening    calls and returns were properly paired up. The hash can be kept in a    register that is stolen from the application throughout its entire    execution. On a call, the value in the register is hashed using an    invertible hash function and the new value is written to the    register. On a return, the register value is passed through the    inverse function and the value prior to the call is restored. A    different hash function per call target is used.-   40. Allow returns if they satisfy the StackGhost transparent xor    scheme [see M. Frantzen and M. Shuey. “Stackghost: Hardware    facilitated stack protection”, In Proc. 10th USENIX Security    Symposium, August 2001].-   41. Allow returns if a StackGuard canary created in the stack was    not modified [see Crispin Cowan, Calton Pu, Dave Maier, Jonathan    Walpole, Peat Bakke, Steve Beattie, Aaron Grier, Perry Wagle, Qian    Zhang, and Heather Hinton, “StackGuard: Automatic adaptive detection    and prevention of buffer-overflow attacks”, In Proc. 7th USENIX    Security Symposium, January 1998].-   42. If the control transfer is due to an exception, validate the    exception handler.-   43. If the control transfer is due to an exception, validate the    exception by maintaining a shadow stack of structured exception    handlers.

The un-circumventable sandboxing provides the necessary mechanism toenforce a full set of rules that can guard against misuses of systemcalls. As there are many system calls with many use models, what isdescribed here is an example of possible rules to sandbox one systemcall—the execve( ) UNIX system call. Other system calls can also besandboxed.

-   44. The allowed system calls do not include the execve system call.-   45. Allow the execve system call if the operation can be validated    not to cause a problem.-   46. Allow the execve system call if the arguments match a given    regular expression.-   47. Allow the execve system call only if the arguments are from a    read-only data section.-   48. Create a further restriction by combining either rules 45 and 47    or rules 46 and 47.-   49. Allow the execve system call to be issued only from specific    modules or functions.-   50. Allow the execve system call.    Although these rules, as described, are composed as a disjunction,    there are many other structures to organize the rules. For example,    the rules can be broken into smaller clauses that are combined using    arbitrary Boolean logic.

Attack Handling

When the next instruction or the control transfer to be executed issuspect or when a system call is invoked in a suspected manner, thereare many possible remedial actions that can be taken. This sectiondescribes a few possibilities. Note that this is not an exhaustive list.

-   1. Log the event and continue execution. This provides an intrusion    detection capability, but does not prevent the intrusion from    succeeding.-   2. Kill the application.

In the next set of actions, the attack is defeated while an attempt ismade to keep the program alive. However, there is no guarantee that aprogram will keep working normally after such an action.

-   3. Kill the offending thread that is asking to execute the suspected    action.-   4. Throw an exception so that the program can bypass the suspected    action.-   5. Unwind the exception stack until a valid exception handler is    found and throw an exception to that particular exception handler.-   6. In a suspected system call, without performing the system call,    continue execution as if the system call returned an error.-   7. In case of an invalid control transfer or an invalid destination    instruction due to a conditional branch, force the branch to not be    taken.-   8. In case of an invalid control transfer or an invalid destination    instruction due to a call instruction, skip the call, simulate the    return of an appropriate return value, and continue execution.-   9. In case of an invalid return address in the stack, unwind the    stack until a valid call frame is found and continue execution.-   10. Continue execution with a different, or more restrictive, set of    rules that will drastically reduce the possibility of damage from an    attack.-   11. Attempt to dynamically modify the program to correct the    violations and make the program conform to the rules. If successful,    continue execution; if not, use one of the previous attack handling    techniques.    Another attack handling mechanism is to delay the continued    execution after handling the attack in order to throttle multiple    attacks into the system.

Security Policy

All of the enforceable rules described previously cannot be applied toall programs. While most broad rules are satisfied by many applications,compliance with some of the more restrictive rules has a significantvariation among different programs. Furthermore, in a few programs thereare exceptional circumstances that lead to violations of even the mostgeneral rules. Thus, there are tradeoffs between program freedom andsecurity: if rules are too strict, many false alarms will result whenthere is no actual intrusion. Furthermore, there are many choices ofremedial actions that can be made when a potential attack is detected.

Since monitored program execution can enforce multiple rules, eachprogram requires a security policy that will dictate which of theserules are to be applied and what actions to take when a possible attackis detected. This section discusses the potential design space increating a policy to provide significant protection without undue burdenon the user and without annoying side effects such as false positives.

A security policy for an application, which is stored in a securitypolicy database, comprises:

-   1. A list of rules that are active. For example, since most programs    do not generate dynamic code, rules 5 to 18 can be turned off.-   2. A list of rules that apply only to a specific instance identified    by a combination of:    -   a. The module name of the source, which is mainly used for RCT    -   b. The module name of the destination, which is mainly used for        RCO or RCT    -   c. The source address, which is mainly used for RCT    -   d. The destination address, which is mainly used for RCO or RCT    -   e. The type of instruction, which is mainly used for RCT    -   f. The type and origin of the arguments in a system call, which        is mainly used for UCS.-    When the source and the destination addresses are relative to the    starting address of a DLL, the exceptions are valid even when the    DLL is relocated. Note that this is only a partial list and other    filters can also be applied to limit the rules.-   3. A collection of data that is required by some of the active    rules. For example, the rule 14 requires known trampoline    instruction sequences.-   4. Exceptions to the rules. These exceptions can be specified using    the same set of filters as specified in 2.-   5. The actions to take when a violation is detected.

FIG. 2: Attack Resilience

The program shepherding techniques described above can thwart a largeclass of typical attacks. FIG. 2 summarizes the contribution of eachprogram shepherding technique toward stopping different types ofattacks. The three right-hand columns represent the three techniques. Abox containing “STOPPED” indicates that that technique can, in general,completely stop the attack type above. The term “HINDERED” indicatesthat the attack can be stopped only in some cases. The left-to-rightorder of the techniques indicates the preferred order for stoppingattacks. If a further-left box completely stops an attack, the systemdoes not invoke techniques to its right (e.g., sandboxing is capable ofstopping some attacks of every type, but it only uses it when the othertechniques do not provide full protection).

Under the column labeled “Attack Types”, the categories of attacks aresuccessively subdivided.

They are first subdivided into Existing Code and Injected Code. AnInjected Code Attack forces the program to execute malicious code thatis inserted as data by the attack itself. For Injected Code Attacks, theCode Origin policy disallows execution from address ranges other thanthe text pages of the binary and mapped shared libraries. This stops allexploits that introduce external code, which covers a majority ofcurrently deployed security attacks.

Existing Code is further divided into Chained Calls and Other Transfers.An attacker may be able to execute a malicious code sequence bycarefully constructing a chain of procedure activation records, so thata return from one function just continues on to the next one. This canbe stopped by requiring that return instructions target only call sites,which comes under Restricted Control Transfer policy.

Other Transfers divide into Returns on one hand and Calls or Jumps onthe other. Multiple return value attacks that are not chained can bedealt with effectively by a combination of Restricted Control Transferpolicy and Uncircumventable Sandboxing.

Calls and jumps break down into inter-module and intra-module. Forinter-module transfers, the system looks at entry and exit pointsspecified by the modules. Attacks that violate these specifications arestopped by using Restricted Control Transfer policy. OtherwiseSandboxing is needed.

Attacks that use intra-module manipulation can be dealt with more easilywhen symbol information is available or can be deduced by analysis. Ifthe attack has mid-function flow violations, then it is stopped byRestricted Control Transfer policy. Otherwise, or if symbol informationis not available, Sandboxing is needed. Note that the above-discussedclassification is neither exact nor comprehensive (nor required by thepresent invention), but reflects the current trends and methods used byattackers.

Example Implementation

One example of a method for implementing the present invention is byinstrumenting the application and library code prior to execution inorder to add security checks around every branch instruction andprivileged operation. A few possible embodiments of such animplementation are described at an abstract level in FIGS. 4, 5, and 6.Another possible implementation is to use an interpreter or emulator.Interpretation is the most straightforward solution to provide completemediation of control transfers on native binaries. It is a natural wayto monitor program execution because every application operation iscarried out by a central system in which security checks can be placed.One possible embodiment using an interpreter is described in detailstarting from FIG. 8.

Another example of an implementation of the present invention is to usea low-overhead software system that creates, examines, and modifiesexecution traces. Such a system provides the exact functionality neededfor efficient program shepherding. These systems begin with aninterpretation engine. To reduce the emulation overhead, nativetranslations of frequently executed code are cached so they can bedirectly executed in the future. An aspect of the innovation is the useof caching to eliminate most of the dynamic invocations of the securitychecks. Because of caching, many security checks need be performed onlyonce, when the code is copied to the cache. If the code cache isprotected from malicious modification, future executions of the trustedcached code proceed with no security or emulation overhead. One possibleembodiment using such a code cache is described starting with FIG. 12.

FIG. 1: Block Diagram of the Abstract Components

A system that implements Program Shepherding can be divided intomultiple components, as described in FIG. 1. These components consistof:

-   1. An application database (220) contains the application (221) in    the form of source code, object code, or a binary file.-   2. A security policy database (210) that stores both fundamental    conventions that apply to all programs as well as    application-specific security policies (211).-   3. An analysis processor (230) that analyses the program to gather    the information needed for program shepherding, identifying what    security policies should be applicable to the application as well as    creating application-specific security policies.-   4. An instrumentation processor (231) that inserts the necessary    checks in the program so that when the code is executed, the    necessary tests are invoked with the information needed to carry    them out.-   5. An execution processor (232) that executes the instructions of    the application on the given hardware platform.-   6. A monitor processor (233) that guarantees all the necessary    security checks are reliably executed without the risk of being    bypassed.-   7. An enforcement processor (234) that performs each security check,    flags security policy violations and performs attack handling    options.

FIG. 3: Creating Application-Specific Policies

FIG. 3 is a block diagram that describes some of the alternative pathsavailable in creating an application-specific policy.

The security policy database (210) has two components: fundamentalconventions that apply to all the programs (212) andapplication-specific policies (213). Application-specific policies arecreated by either analysis of the source code (221) in the source codedatabase (220), by the Analysis processor (230) or by firstinstrumenting the application (231), then executing it (232) and finallygathering profile information (250) which is analyzed (230) to createthe application-specific policy.

There are many possible embodiments of Program Shepherding. Most of thevariations center on how and when analysis and instrumentation areperformed. The example embodiments in FIGS. 4, 5, 6 and 7 show only afew combinations of analysis and instrumentation. Since analysis andinstrumentation can be decoupled, there are many other validcombinations of analysis and instrumentation points.

FIG. 4: Analysis and Instrumentation of Source Code

FIG. 4 is a block diagram that describes how analysis andinstrumentation can be performed on source code. Note that it is notnecessary for both analysis and instrumentation to be performed at thesame level. For example, it is perfectly possible to perform analysis onthe source code but instrumentation on the binary. As depicted in FIG.4, the application database (220) contains the source code (222) of theapplication. The source code is analyzed by the analysis processor(230). This analysis information may be fed into the security policydatabase (210) to form an application-specific security policy. Theinstrumentation processor (231) works on the source code with theinformation provided by the analysis processor as well as the securitypolicy (211) and instruments the program with the appropriate checks.The compiler (251) processes the resulting modified source code into anInstrumentation Binary. At runtime (252), the application is executed(232) alongside the monitoring of control transfers (233). The necessarypolicy violation checks are done by the enforcement processor (234)using the policy information (211) from the policy database (210).

FIG. 5: Analysis and Instrumentation by the Compiler

FIG. 5 is a block diagram that describes how analysis andinstrumentation is performed in the compilation process. As described inFIG. 5, the analysis (230) and instrumentation (231) is performed withinthe compiler (252). The application database (220) provides the compilerwith the source code (222). The security policy database (210) providesthe compiler with the security policy (211) and optionally can get backinformation on application-specific policies. At runtime (252), theapplication is executed (232) alongside the monitoring of controltransfers (233). The necessary policy violation checks are done by theenforcement processor (234) using the policy information (211) from thepolicy database (210).

FIG. 6: Analysis and Instrumentation of the Binary

FIG. 6 is a block diagram of an embodiment where the analysis andinstrumentation is performed on the binary image. The applicationdatabase (220) provides the source code (222) which is first compiledand linked (251) to create an executable file. The executable is used bythe analysis processor (230) and the information is passed to theinstrumentation processor (231) and optionally to the security database(210) to form an application-specific security policy. Theinstrumentation processor, using the information from the analysisprocessor as well as the security policy (211), instruments theapplication binary. Note that the analysis processor can either pass theanalyzed binary to the instrumentation in a coupled mode or decoupledwith instrumentation where the instrumentation processor works on anunmodified binary and a saved application-specific policy. At runtime(252), the application is executed (232) alongside the monitoring ofcontrol transfers (233). The necessary policy violation checks are doneby the enforcement processor (234) using the policy information (211)from the policy database (210).

FIG. 7: Runtime Analysis, Instrumentation

FIG. 7 is a block diagram of an embodiment where all the processing isdone at runtime. The two detailed embodiments described later in thedocument closely resemble this configuration. However, note that forboth detailed embodiments, the analysis processor can be applied beforeruntime to create an application-specific policy which is used atruntime. In this embodiment described in FIG. 7, analysis (230) andinstrumentation (231), as well as monitoring (233), enforcement (234)and execution (232) are done at runtime (252). The application database(220) provides the source code (222) which is first compiled and linked(251) to create an executable file. However, this executable file has noprogram shepherding-specific information. Program Shepherding is fullyimplemented at runtime using a security policy (211) provided by thepolicy database (210).

Embodiment Based on a Runtime Emulator

To help clarify various aspects of the invention, the following sectionsprovide an example embodiment of Program Shepherding. In thisembodiment, a set of rules, from the Enforceable Rules described above,were selected to demonstrate the general capabilities of the system. Theembodiment closely resembles the rule #1, relaxed as described by #3,for code origins, where code from an application or dynamically loadedlibrary is considered valid, as long as it has not been modified sinceit was loaded. Also, the system uses rules #33 and #34 for restrictedcontrol transfers, allowing a return if its destination is preceded by acall instruction.

FIG. 8 is a block diagram of this embodiment while FIGS. 9, 10 and 11are a composite flow chart describing the operation.

FIG. 8: Block Diagram of the Runtime Emulator

FIG. 8 is an overview block diagram of an example embodiment. Theexecutable program starts out on a disk or other external storage (220)and is then loaded or mapped into computer memory (211) where it wouldnormally be executed (212). Instead, Program Shepherding inserts itselfat the beginning of this process to both analyze the program and to setup the Program Shepherding execution Monitoring process (235).Meanwhile, the Enforcement Processor (234) starts up by reading in thecurrent security policy (210). The analysis mentioned relative to (235)can augment or modify the security policy.

In its simplest terms the system then runs the code on the fly in anexecution area (213) while all data is accessed in the same location asthat done in the original program. This can be done by simulating oremulating each instruction in the program. Policy enforcement can thenbe easily applied on the fly between executions of the instructions. Inparticular, in this mode of operation it is very easy to check thevalidity of control transfer targets, since the system must examine themin any case.

The Analysis, Instrumentation and Monitor Processor (235) carries outthis process identifying the next instruction to the Execution Processor(232) for actual execution. Before execution of an instruction in theExecution Processor (232), The AI&M Processor (235) may invoke theEnforcement Processor (232) for policy enforcement. Policy validation inthe executing group of instructions can be accomplished either by codeinlined by the AI&M Processor, in cooperation with the EnforcementProcessor, or by calling directly to the Enforcement Processor.

FIG. 9: System Setup

FIG. 9 is a flow chart that describes how control transfer in to theapplication, either at the start or via a kernel mediated controltransfer, is handled. The actions in this flow chart belong toinstrumentation, monitoring and enforcement. The system begins at (412)by creating a list of pages for valid loaded code (430) that iswrite-protected (431). This is the Read-Only Page List or ROPL. This ishow the system identifies the code that remains unmodified after it isloaded into memory. The system changes the permissions on a pagecontaining such code to write-protected and then puts the page on theROPL list to keep track of it. Any page on the ROPL list contains codethat has been unmodified since loading. At (432), the system modifiesinterrupt handlers and kernel control transfers to return to the AI&MProcessor, preventing control from reaching the original code throughthese routes. Finally at (433) it finds the first instruction in theprogram and then goes on to (414) in FIG. 10.

When the kernel passes control to the Runtime system, it enters at(410). If this entry is due to an exception (420), the system checks ifit was due to an attempted write to protected memory (421). If thetarget was the ROPL or other internal data structures (422), the systemthrows an exception for writing to invalid memory (411). Otherwise thesystem checks to see if the attempted write was to a page listed in theROPL (423). If not, the system determines the instruction the kernelshould transfer to (424) and carries on with (414) in FIG. 10.

If the write was to a page in ROPL at (423), the system implements asimplified policy that does not support writing to code pages, in whichlater use of code on such a page will result in a policy violation at(416) in FIG. 10.

At this stage the system does the following:

-   -   Unprotects the ROPL (425) using a system call to change the        permissions on the page that contains it.    -   Removes the page from the ROPL (426), a standard list unlink        operation    -   Re-protects the ROPL (427), again using a system call    -   Makes the removed page writeable (428)    -   Cleans up after the exception (429)    -   Transfers control back to the kernel (413)        After this there is no longer any guarantee that the code on        that page is unmodified. That is why it was just removed from        the ROPL.

FIG. 10: System Operation

FIG. 10 is a flow chart that describes the basic execution loop in theemulation system. The actions in this chart include monitoring,execution and enforcement activities.

Here the system begins at (414) with a given instruction address. Thisis the entry for external control transfers. Then it determines if thegiven instruction address refers to code that might have been tamperedwith. This is determined by seeing if the code is contained within apage in the ROPL (440). If not, it stops with a Code Origins securitypolicy violation (416). As described above, this ensures that the systemonly executes code that has been unmodified since loading.

Otherwise the code is valid and the system next checks at (441) if thecurrent instruction is a return. If not, the system continues at (444)described below.

If it is a return, the system determines if the return destination isvalid. There are a number of ways to do this as described in the rules.In this case, at (442), the system looks up the instruction justpreceding the return destination. At (443) the system checks if thatinstruction is a call. This is a necessary requirement for validity, butin general it is not sufficient. If it is not a call, the system stopswith a Restricted Control Transfer policy violation at (415). If it is,the system continues at (444).

At (444) the system determines if the current instruction is a systemcall and if so (417) pre-processes the system call as described in FIG.11. Then at (455) the system executes the instruction. Following that,at (456), if the instruction is not a system call, the system finds thenext instruction to execute (463) and then proceeds to (440). If thatjust executed instruction was a system call with an associatedpost-check (457), the system executes the post-check at (458).

If the executed instruction was a Load DLL (459), then the systemcollects the list of pages containing the code that was just loaded andsets it up like originally loaded code by adding it to the ROPLunmodified code list. To do this the system unprotects the ROPL (460),write-protects the pages associated with the loaded DLL and adds them tothe ROPL (461), and then re-protects the ROPL (462). At (463) the systemfinds the next instruction to execute and then continues on at (440) asabove.

FIG. 11: System Call Pre-Processing

FIG. 11 is a flow-chart that describes the un-circumventable sandboxingperformed on the program. These activities mainly belong to monitoringand enforcement. If the instruction is a system call, the systemdetermines if there is an associated pre-check (445) and if so, executesthat check (446). If the instruction is to change the memory protectionstatus of a memory page (447), the system checks to see if it is to makeit writeable (448). Such a change removes the guarantee that the code onthat page is unmodified, so it must be removed from the ROPL unmodifiedpage list (449). The system does this by unprotecting the ROPL (450),removing that page from the ROPL (451) and re-protecting the ROPL (452).For any system call that is setting a kernel mediated control transfer(453), the system modifies the target of that transfer to a location inthe IA&M Processor that will handle it (454). This ensures that controldoes not reach the original code.

Embodiment Based on a Software Code Cache

Another embodiment of the present invention implements ProgramShepherding using a Software Code Cache, a technique known topractitioners in the art. An overview of the embodiment using a SoftwareCode Cache is provided in FIG. 12, with the Code Cache represented bythe two blocks (242) and (241). The security policy is stored in (210).

In a normal system, code is copied from external storage (220), such asa disk, placed in memory and then executed directly from memory by theprocessor. In the Code Cache based system, the code is copied frommemory in groups called fragments, blocks or “basic blocks,” into such aCode Cache. These blocks are executed by the Execution Processor (232).In some embodiments, this is the only way user or application code isexecuted.

The blocks are created by the Block Builder (238), while the TraceBuilder (239) creates groups of blocks called traces.

In terms of security policy, Restricted Code Origins is implemented byadding checks at the point when the system copies a basic block into thecode cache. The decisions associated with such security checks arecarried out by the Analysis and Enforcement processor (234), whichobtains policy from (210).

Checking code origins involves negligible overhead because code needonly be checked once prior to insertion into the code cache. Once in thecache no checks need to be executed. Code origin checking requires thatthe runtime system know whether code has been modified from its originalimage on disk, or whether it is dynamically generated. This is done bywrite-protecting all pages that are declared as containing code onprogram start-up. In normal ELF binaries, code pages are separate fromdata pages and are write-protected by default. Dynamically generatedcode is easily detected when the application tries to execute code froma writable page, while self-modifying code is detected by monitoringcalls that unprotect code pages. If code and data are allowed to share apage, a copy is made of the page, which is write-protected, and then theoriginal page is unprotected. The copy is then used as the source forbasic blocks, while the original page's data can be freely modified. Amore complex scheme must be used if self-modifying code is allowed. Herethe runtime system must keep track of the origins of every block in thecode cache, invalidating a block when its source page is modified. Theoriginal page must be kept write-protected to detect every modificationto it.

A software code cache is an ideal infrastructure for an efficientimplementation of RCT. For direct branches, the desired security checksare performed at the point of basic block linking. If a transitionbetween two blocks is disallowed by the security policy, they are notlinked together. Instead, the direct branch is linked to a routine thatannounces or handles the security violation. These checks need only beperformed once for each potential link. A link that is allowed becomes adirect jump with no overhead. Indirect control transfer policies add noperformance overhead in the steady state, since no checks are requiredwhen execution continues on the same trace. Otherwise, the hash tablelookup routine translates the target program address into a basic blockentry address. Only validated control transfers will be entered in thehash tables, resulting in no extra overhead for security checks forindirect transfers that only examine their targets. Policies that alsoexamine the type of a control flow transition can be implemented using aseparate hash table to look up the target for validation for differenttypes of indirect control transfers (return instruction, indirect calls,and indirect branches). This enables type-specific restrictions withoutsacrificing any performance when execution continues in the code cache.These context-insensitive policies can be easily enforced with minimaloverhead because they are always valid after initial verification,therefore they can be cached and cheaply evaluated with minimalexecution overhead. Any policies that need to examine both the sourceand the target of a transition can be implemented using a separate hashtable for each source location.

When required by the security policy, the monitoring processor insertssandboxing into a basic block when it is copied to the code cache. Intraditional sandboxing, an attacker can jump to the middle of a blockand bypass the inserted checks. The system only allows control flowtransfers to the top of basic blocks or traces in the code cache. Anindirect branch that targets the middle of an existing block will missin the indirect branch hash table lookup, go back to the monitoringprocessor, and end up copying a new basic block into the code cache thatwill duplicate the bottom half of the existing block. The necessarychecks will be added to the new block, and the block will only beentered from the top, ensuring that the system follows the securitypolicy. Restricted code cache entry points are crucial not just forbuilding custom security policies with un-circumventable sandboxing, butalso for enforcing the other shepherding features by protecting theruntime system itself.

There is a multitude of possible and often conflicting policies that canbe implemented with the three techniques of program shepherding. Thus,the embodiment, as described, closely resembles only a selected set ofrules, and is only a demonstration of the general mechanisms of theinvention applied to these policies. For code origins the rule #2 withthe relaxation described in #3 was used. There is also support for rule#5 as an application-specific policy. The restricted control transfersis demonstrated using the rules #22, #24, #26, #27, #28 restricted asdescribed in #31, #29 restricted as described in #31, #32, and #36.Un-circumventable sandboxing demonstrates how to check the system callsand exceptions that are required to implement the above rules. Forexample, the load DLL system call is sandboxed in order to implementrule #3.

FIG. 12: Overview

FIG. 12 is an abstract block diagram of the second embodiment. This isan expansion on the configuration described in FIG. 7 where analysis,instrumentation, monitoring, execution and enforcement are all done atruntime. However, note that an analysis pass performed before runtimecan be used to create an application-specific policy.

Execution is divided into two modes: Runtime System Mode and ApplicationMode. The Runtime System controls the overall operation: puttingapplication code fragments into the Code Cache, starting those codefragments running in Application Mode and controlling security policy.

The system is designed so that the application code running inApplication Mode runs in its own context to preserve transparency, andlimiting interaction with code operations and data allocations done bythe Runtime System. Hence there is a context switch between transitionsbetween Application Mode and Runtime System Mode.

Other parts of the system are designed to avoid context switches bystaying within Application Mode as long as possible. These include thedirect linking of blocks within the Code Cache, the Indirect BranchLookup Table and the Trace Cache, explained in more detail below.

Runtime System Mode corresponds to the top half of FIG. 12 above thecontext switch component, (240). Application Mode corresponds to thebottom half, below (240), including the Code Cache, consisting of theBlock Cache (242) and the Trace Cache (241), and those Shepherdingroutines that are executed without performing a context switch back tothe Shepherding half, including the Indirect Branch Lookup Table (243),which is implemented as one or more hash tables, a well-known concept inthe art.

For the two modes, the system assigns each type of memory page theprivileges shown in the following table:

Page Type Runtime System Mode Application Mode Application Code ReadRead Application Data Read, Write Read, Write Shepherding Code CacheRead, Write Read, Execute Shepherding Code Read, Execute ReadShepherding Data Read, Write Read

Runtime System data includes the Indirect Branch Lookup Table, (243),and other data structures.

All Application and Runtime code pages are write-protected in bothmodes. Application data is, of course, writable in Application mode, andthere is no reason to protect it from the Runtime System, so it remainswritable in that mode. Runtime data and the code cache can be written toby the Runtime itself, but they must be protected during ApplicationMode to prevent inadvertent or malicious modification by the userapplication.

If a block copied to the Code Cache contains a system call that maychange page privileges, the call is sandboxed to prevent changes thatviolate the above table. Program Shepherding's UncircumventableSandboxing guarantees that these sandboxing system call checks areexecuted. Because the Runtime's data pages and the code cache pages arewrite-protected when in Application Mode, and the system does not allowuser application code to change these protections, it is guaranteed thatthe Runtime System's state cannot be corrupted.

If the Operating System detects an access violation, it goes to theexception handler in the Enforcement Processor, (234). Morespecifically, this is dealt with in FIG. 23. The system could alsoprotect the Global Offset Table (GOT) by binding all symbols on programstartup and then write-protecting the GOT.

The Indirect Branch Lookup Table is key to the working of the system.The system does not modify how a program computes addresses, but it doesmodify how the addresses are used in branch instructions. Since werelocate code from its original position in memory to a code cache, theIndirect Branch Lookup Table provides the crucial mapping from thoseoriginal addresses to the new location of the code in the Code Cache. Sowhen the original code does a branch to an address, the system modifiesit to branch to the new location of that code in the Code Cache. A keydesign factor that keeps execution within Application Mode, reducing thenumber of context switches, is how direct and indirect control transfersare handled.

Direct control transfers, where the target is known before the programruns, are dealt with entirely within the Code Cache which includes theBlock Cache (242) and the Trace Cache (241). This is done by checking ifthe Restricted Control Transfer policy is satisfied and if so, bymodifying the target address to refer to the copy of the code in theCode Cache rather than the original code.

Indirect control transfers, where the target is not known until runtime,require the use of the runtime Indirect Branch Lookup Table, (243).While the original code jumps directly to a target address, the copy ofthat code has been modified to obtain its actual target by looking it upin this table. Given an address referring to the original code, theIndirect Branch Lookup Table returns a reference to the copy of thatcode in the Code Cache. This approach preserves correct policy sinceentries are only added to this lookup table if they satisfy the policy.

If a target is not known to satisfy policy as above, the system does acontext switch and returns to the Monitor Processor, (237). The Monitorcalls the Enforcement Processor (234) to see if the target satisfiespolicy and whether it should be added to the Indirect Branch LookupTable, as detailed below.

The system applies policies regarding control flow for both direct andindirect control transfers. Direct transfers are monitored as a targetblock is copied into the Code Cache. Indirect transfers are monitoredindirectly by policies determining what entries are placed in the BranchLookup Table, (243). The Trace Cache basically allows for sequences ofbasic blocks that can execute entirely within Application Mode withoutincurring a context switch.

FIG. 13: Monitor Processor

FIG. 13 is a flow chart that describes most of the monitoring andinstrumentation activities in the Instrumentation and Monitor Processor.This is the main runtime loop that is activated when the control istransferred either at program startup, from a kernel mediated controltransfer, or from the code cache. The Monitor processor is the first oneexecuted when an application is protected by Program Shepherding. TheMonitor also deals with newly discovered target addresses which arisefrom the Code Cache (FIG. 15) through stubs or failed lookups of theIndirect Branch Table. The Block Builder has placed a stub at the end ofa basic block when there was a branch to a new target.

When the program starts at the bottom of FIG. 13 (501), all the validcode pages are identified and a Read Only Page List is created (502),and these pages are write-protected (503). Any interrupt handlers andkernel control transfers are setup such that the control will betransferred to the monitoring processor rather than directly to theprogram address (504). Finally, the starting address of the program isfound (505) and basic block building is started from that address (549).

When the Monitor is started directly from the OS (545), the system getsthe starting address of the kernel entry point (546) and at (549) passesthat to the Block Builder for it to build a basic block starting at thataddress. The Block Builder (see FIG. 14) creates the block and places itin the Code Cache (561) of FIG. 14. After that the Block Builder tellsthe Code Cache (FIG. 15) to start executing the new block.

The Monitor is also entered at (565) from the Code Cache (FIG. 15) whenit encounters an exit stub at (523) of FIG. 15. In that case the Monitorgets the target address (540) and then queries the Enforcement Processor(FIG. 20) whether this control transfer is permissible (547). If so, itcontinues by seeing if the Code Cache already has a fragment starting atthe destination address (541). If it does, it overwrites the exit stubwith a branch to the corresponding block (542), setting a directblock-to-block link, and then tells the Code Cache at (564) to start upthat block. If the control transfer is not permissible, the EnforcementProcessor (234) of FIG. 12 deals with the problem without returning(637-FIG. 20).

The Monitor is also entered from the Code Cache when an indirect branchlookup has failed at (563). The first step in this case is to verify thebranch satisfies the security policy for this indirect branch (548) bygoing to the Enforcement Processor, FIG. 20. Then it checks if the CodeCache already has a fragment at this target/destination address (543).If not, it directs the Block Builder to build a new block (549) and runit (562-FIG. 14). Otherwise, a fragment already exists for the targetaddress, so at (544) the system updates the corresponding IndirectBranch Table with that looked-up fragment address and directs the CodeCache to start executing the destination fragment (566). As above, at(548) if the target address is not permissible, the EnforcementProcessor (234) FIG. 12 takes over.

FIG. 14: Block Builder

FIG. 14 is a block diagram that describes the process of building abasic block in the basic block cache. The basic task for the BlockBuilder is to copy a sequence of consecutive instructions starting atthe input target address and stopping at a branch instruction. Inaddition, the Block Builder may modify some instructions and add inothers. It is also part of the trace building process. The block builderis crucial in enforcing Sandboxing, since it adds in the associated preand post checks. It also verifies the Code Origins policy and theRestricted Control Transfer policy.

The Block Builder gets passed in a target address via (567) which itfirst uses to construct a block starting at that address (550). It thenasks the Enforcement Processor to check that the Code Origins policy issatisfied for that new block (652). Next at (553) the system checks theblock for any instructions that require pre or post un-circumventablesandboxing checks and, if needed, inserts the checks at (554). Thesystem then checks the final branch instruction in the block (555). Ifit is an indirect branch (559), the system inserts indirect branchlookup code (560) at the end of the block, inserts the block into theCode Cache (561) and then tells the Code Cache to start executing thisnew block (562). If it is a direct branch (555) and the target is not inthe Code cache (556), the system places an exit stub at the end of theblock (557). The stub ensures that this new target address will getprocessed later. If the target is a block already in the Code Cache, itcalls the Enforcement Processor to verify the restricted controltransfer policy (653). If that passes, at (551) the system checks ifthis block should be a trace head. If so, at (552) it allocates a tripcount location and inserts trip count increment and check code. Finally,since this address has been verified as passing the restricted controltransfer policy, the system makes a direct link from the new fragment tothe existing one (558). In any case, the system concludes by insertingthe block into the Code Cache (561) and telling the Code Cache to startexecuting the new block (562).

FIG. 15: Code Cache

FIG. 15 is a block diagram that describes the actions carried out in thecode cache, which comprises both the basic block cache and the tracecache. This diagram also includes the indirect branch lookup component.This depicts the main execution loop in the steady state when theworking set of the application is in the code cache and there are noabnormal control transfer requests.

When the Monitor Processor decides to execute a block or fragment, itsends a request to the Code Cache along with a reference to the fragmentto be executed. If the Monitor does not have a block reference, it firstcalls the Block Builder (FIG. 14) to obtain one. The Code Cache thenobtains via (568) the fragment or block at (510) and goes to the TraceChecker at (527) to take care of possible trace building described inFIG. 16. Then at (516) the Code Cache directs the Execution Processor(FIG. 18) to execute the indicated fragment with the following possibleexit outcomes indicated at (520):

-   1. The block execution reaches a stub at (523) via the choice at    (521), in which case instruction information is saved (522) and    execution goes through a context switch (569) to the Monitor    Processor at 565 in FIG. 13, which deals with this case.-   2. The block execution reaches a direct branch to another fragment,    the upward path from (523), in which case control just passes    directly to that fragment as if it were starting a block directly    from the Monitor Processor.-   3. The block execution reaches code that looks up an indirect branch    target at (243) also via the choice at (521), which further consists    of the actual lookup of the target address (526). If the target    address is in the table (528), the code passes control to the    fragment reference from the table, as in case 2. If the target    address is not in the table, execution returns back through a    context switch (586) to the Monitor Processor at 563 in FIG. 13.

FIG. 16: Trace Check

FIG. 16 is a flow chart that describes the process of identifying when atrace should be built. This requires some bookkeeping at candidate traceheads. When a hot path is detected at a trace head, building of a newtrace is started.

Traces are sequences of basic blocks that can execute one after anotherwithout going back to the Monitor Processor and incurring a contextswitch. The creation of a trace is begun by finding a block to start thetrace with, called a trace head. The system comes in via (530) anddetermines if the block is a trace head at (511) and if so, does a tracesetup—just below. One way of determining if a block is a trace head isif it is the target of a backward branch or the target of an exit froman existing trace.

The trace set up is as follows:

-   -   Increment the block trip count at (512); and    -   If the trip count has reached its threshold (513), turn trace        building on (514).        If trace building is turned on at (519), the system, at (528),        goes to the Trace Builder (FIG. 17). Finally, the system returns        from the Trace Check (531).

FIG. 17: Trace Builder

FIG. 17 is a block diagram that describes the process of building atrace. A trace is built simultaneously while executing the identifiedhot path. When a trace ending condition such as a backward branch orstart of another trace is detected the current trace is terminated. Whenbuilding a trace, the system connects a basic block that ends in anindirect branch by inserting a check to ensure that the actual target ofthe branch will keep execution on the trace. This check is much fasterthan the hash table lookup, but if the check fails the full lookup mustbe performed. The superior code layout of traces goes a long way towardamortizing the overhead of creating them.

From the Code Cache the system enters this subsection via (532) with thegoal of copying a block to the Trace Cache. This starts with adetermination of whether the trace ending condition is met (570). Oneway to determine the end of a trace is if the final branch of thefragment is a back branch or if it goes to another trace or a tracehead. If it is not a trace end, it copies the fragment into the currenttrace (571) and inspects the last instruction in the previous fragment(572). If that is a conditional branch or an indirect branch (573), itinlines a test with an exit stub (574). For a conditional branch, thetest is the condition. For an indirect branch, the test determines ifthe current target of the indirect branch stays on the trace. If it is atrace end at (570), the system first (575) updates the indirect branchtables to associate the trace with the beginning fragment. Then itupdates the links of fragments pointing to the beginning fragment sothat they now point to the trace instead (576). It then turns tracebuilding off at (577). Finally the system returns back to the code cachewith the fragment copied to the trace cache (533).

FIG. 18: Execution Processor

FIG. 18 is a flow chart of the execution processor which executes basicblocks or traces. The execution processor also performs theun-circumventable sandboxing. Execution of the instructions that do notimpact the security checks or operation of the code cache is donenatively for speed. However, instructions can also be simulated oremulated. The Execution Processor executes a block or a trace. The Blockand Trace Builders have constructed their respective blocks and tracesso that the process is automatic once it is started. The diagram here isdesigned to show what happens within that execution process,specifically how the pre and post checks are performed. The execution ofthe “next instruction” is, of course, automatic with a native executionprocessor.

Execution begins at (515), via (534), with the first instruction in thefragment. As the fragment executes it may reach code that was insertedin the fragment by the system. Such code includes semantic Sandboxingchecks before and after system calls as well as exit instructions. Ifblock execution reaches checking code previously inserted before orafter a system call, this is indicated by (517). At (518) the checkingcode gathers information for the particular check and transfers controlback to the Enforcement Processor at (526), which either returns tocontinue executing the next instruction, via (506), in the remainder ofthe block or if the checks have failed, it does not return. At (525) ifexecution reaches an exit instruction, the system returns (535).Otherwise, the current instruction is executed at (529), the nextinstruction is fetched at (506) and the process repeats at (517).

FIG. 19: Code Origins

FIG. 19 is a flow diagram that describes the enforcement of the selectedcode origins test in the Enforcement processor. The implemented codeorigins test closely resembles rule #2 with the relaxation described inrule #3. There is also support for rule #5. The basic idea here is toidentify code that is trusted and to put such code under hardwarewrite-protection, which is usually only available at a page level. Suchtrusted and protected code is then used as the source for building basicblocks.

Because a page can sometimes contain both code and data, it is possibleto have legitimate writes to code pages. In that case, the system needsto allow the write while still preserving the integrity of the code thatis on the same page. This is accomplished by creating a read only copyof the code page, called the shadow page, before the write is done.

The system uses the following data structures:

ROPL: Read Only Page List—all loaded code is protected at a page leveland such pages are placed on this list. Such code includes initiallyloaded program code as well as code from dynamically loaded libraries.Unloaded libraries, of course, are removed from the list when they areunloaded.PMPL: Partially Modified Page List—all ROPL pages that have beenmodified are placed on this list. Each page on this list has a protectedshadow page, which is used as the source for creating basic blocks.After the write is allowed to occur, the system must verify that no codewas modified. If the relevant code on the two pages is the same, thenthe write did not modify the code in the particular block we areconcerned about.

The Monitor provides an address at (617), via the entry at (536), forthe purposes of verifying the validity of the code starting there. Ifthe address is on a page in the ROPL (610), then it is trusted. Thesystem then does one further check at (615) to see if there is a memorypage boundary between the current address and the end of the currentblock. If so, the system gets the address of that next page at (616) andrestarts the process at (610). If not, the system returns that the checkwas satisfied (537). If the address was not from a ROPL page, then thesystem determines if the address is on a PMPL page at (611). If so, thesystem compares (613) the instruction at the address in the PMPL pagewith the corresponding instruction in the shadow page, found at (612).If they are the same, it means that no code from this block has beenmodified so the system proceeds with (615) as above. If the address isnot from a page in PMPL or the comparison fails, the system checks foran application-specific override policy at (614). If there is one and itis satisfied, the system proceeds to (615). Otherwise, it signals apolicy violation.

FIG. 20: Restricted Control Transfer

FIG. 20 is a flow chart that describes the restricted control transferrules that were implemented in this embodiment to demonstrate thegeneral concept of restricting control transfer. Activity of thisdiagram belongs to the enforcement processor. The code cacheinfrastructure makes monitoring control flow transfers very simple. Fordirect branches, the desired security checks are performed at the pointof basic block linking. If a transition between two blocks is disallowedby the security policy, they are not linked together. Instead, thedirect branch is linked to a routine that announces or handles thesecurity violation. These checks need only be performed once for eachpotential link. A link that is allowed becomes a direct jump with nooverhead.

There are three types of control transfers that can occur duringexecution in the Code Cache: a direct branch, an indirect branch (withspecific cases indirect call, indirect jump, and return) andnon-explicit control flow. Indirect control transfer policies add noperformance overhead in the steady state, since no checks are requiredwhen execution continues on the same trace. Otherwise, the hash tablelookup routine translates the target program address into a basic blockentry address. A separate hash table is used for different types ofindirect branch (return instruction, indirect calls, and indirectbranches) to enable type specific restrictions without sacrificing anyperformance. Security checks for indirect transfers that only examinetheir targets have little performance overhead, since the system placesin the hash table only targets that are allowed by the security policy.Targets of indirect branches are matched against dynamically resolvedDLL entry point symbols to enforce restrictions on inter-segmenttransitions. Targets of returns are checked to ensure they target onlyinstructions immediately following call sites.

Finally, Shepherding must handle non-explicit control flow such assignals and Windows-specific events such as callbacks and exceptions. Itplaces security checks at the interception points, similarly to indirectbranches. These abnormal control transfers are rare and so extra checksupon their interception do not affect overall performance. For thisdetermination there are four cases beginning from (640):

-   1. Direct Jump (620): The system determines whether the transfer    destination is within the module (621) and whether the destination    is within the current function (622). If either is determined to be    false, the system proceeds to (634). Obviously if the transfer    destination is not in the same module, then the destination is not    in the same function. So the policy selection here is that transfers    must be within the same function.-   2. Indirect Jump (623): The system determines whether the transfer    origin and destination are within the same module (624). If not, the    system proceeds to (634).-   3. Return Instruction (631): This is satisfied if the return address    (from 632) can be used to look up an address in the Valid Return    Address List, VRAL (633), which is updated by the Block Builder via    FIG. 21. This is an efficient way to determine if the found call has    actually been previously executed. There a number of embodiments    known in the art that could be used here to validate a return    instruction. This test verifies that the return destination was a    proper one, but is not necessarily the immediately previous one. A    more accurate test requires keeping a parallel stack of return    addresses per thread to check against.-   4. Call Instruction (626): Here, at (638), the system goes to the    Call validity check on FIG. 21.

If the policies in the above cases are valid, the system returns withthe Restricted Control Transfer policy satisfied at (625). For anyfailing case above, the system goes to (634) and does a final check forany application-specific override policy that is satisfied. If there isnone that is satisfied, at (637) the system signals a Restricted ControlTransfer policy violation.

FIG. 21: Restricted Control Transfer—Calls

FIG. 21 is a flow chart that expands on the set of rules that restrictsthe control transfer by call instructions. This section handles checkingpolicy for calls, entering at (642). The following is used for returndestination validation, as described above: VRAL: Valid Return AddressList—keeps valid return addresses.

First the system updates the VRAL with the address of the instructionfollowing the call at (618). If the target is a call entry point (627)and the target is within the same module (628), then the policy issatisfied at (636). Otherwise, despite that, if the callee is importedby the current module (629) and exported by the target segment (630),then the policy is satisfied also at (636). If not, if the source is alibrary module (641), then the policy is satisfied (636). This addssupport for callback functions passed to library routines. In all othercases, at (635) the system returns that the call is not valid.

FIG. 22: Un-Circumventable Sandbox Checks

FIG. 22 describes the un-circumventable sandboxing operations performedon system calls. Sandboxing these system calls is necessary to implementthe restricted code origins policy. There may be other system calls thatneed to be sandboxed to support the code cache implementation.

When required by the security policy, Program Shepherding insertssandboxing into a code fragment when it is copied to the Code Cache. Innormal sandboxing, an attacker can jump to the middle of a block andbypass the inserted checks. Program Shepherding only allows control flowtransfers to the top of basic blocks or traces in the Code Cache,preventing this.

An indirect branch that targets the middle of an existing block willmiss in the indirect branch hash table lookup, go back to ProgramShepherding, and end up copying a new basic block into the Code Cachethat will duplicate the bottom half of the existing block. The necessarychecks will be added to the new block, and the block will only beentered from the top, ensuring that the security policy is followed.When sandboxing system calls, if the system call number is determinedstatically, the system avoids the sandboxing checks for system calls itis not interested in. This is important for providing performance onapplications that perform many system calls. Restricted Code Cache entrypoints are crucial not just for building custom security policies withun-circumventable sandboxing, but also for enforcing the othershepherding features by protecting Program Shepherding itself.

This section uses the following data structure: UPPL: User ProtectedPage List. The operations on the UPPL in this diagram keep itup-to-date. The purpose of the UPPL is to assist in properlydistinguishing write exceptions, as described in the next diagram, FIG.23.

The primary entry here at (608) is from the Code Cache to carry outsandbox checks. Each Sandbox check is associated with a system call. Allprogram code pages are write-protected and kept on a Read-Only PageList, ROPL. If a write is made to such a page, the system allows thewrite, but beforehand it makes a write-protected shadow copy.

First the system sees if the system call for these checks is going toturn off write-protection (644). Such protection is on a page basis. Ifso, in (645) it checks if the page includes data for the runtime system?If so, it modifies the system call at (600) so it will return an errorat runtime if this code is executed. Otherwise if the page does notcontain system data, the system checks at (607) if the page on theUser-Protected Page List, UPPL. If not, the check is satisfied.Otherwise, at (609) the system removes the page from the UPPL. If thesystem call is going to turn on write-protection for a page (646), thenthe system adds such pages to the UPPL (647). If the system call is aload of a DLL (601), the system adds all the code pages of the loadedDLL to the read-only page list (602) and then write-protects all suchpages (603). If the system call is an unload DLL (604), the systemremoves all corresponding code pages from both the read-only page list,ROPL, and the partially modified page list, PMPL (605). Finally, at(606), the system removes all the associated shadow pages for the PMPLentries eliminated in (605). At the end (643), the system returns.

FIG. 23: Sandboxing Exceptions

FIG. 23 is a flow diagram of sandboxing access violation exceptions.This is an example of how to sandbox an exception handler. Otherexception handlers may need to be sandboxed to support the integrity ofthe code cache and the enforcement of the security policies. As shownhere, the UPPL and the ROPL assist in distinguishing different types ofwrite exceptions.

This module is entered through an OS exception handler (538) when anaccess-protection violation occurs. The handler checks if the exceptionwas for a write to a read-only page (590). If not, the check issatisfied and the system throws the exception to the application.Otherwise, the system determines if the write was to a page containingruntime system data (591). If so, at (578) it cleans up after theexception and at (592) returns an error for accessing unallocatedmemory. If (591) is not true, at (598) the system sees if the page inquestion is in UPPL. If so, at (579) it cleans up after the exceptionand at (599) returns an error for writing to protected memory. If (598)is not true, the system determines if the page is in the ROPL at (593).If not, the system throws the exception to the application. Otherwise,the page is on the read-only list, ROPL. The system makes a shadow copyof the page (594), write-protects the shadow (595), unprotects the ROPLand PMPL lists, moves the original page from the ROPL to the partiallymodified page list, PMPL, re-protects the ROPL and PMPL (596), and turnsoff the page's write-protection (597). The system then proceeds to (589)to finish (539) by returning. This allows the original page to containdata that is modified. If the Block Builder goes to copy code from anaddress on the original page, it uses the write-protected shadow pageinstead.

FIG. 24: Context Switch

FIG. 24 is a block diagram of the context switch that is performed whencontrol is transferred from (to) application mode to (from) runtimesystem mode. Context switching is a common operation that is necessarywhen transferring control from one execution context to another.Basically, one needs to save the current context, so it will beavailable to restore later, and then restore the target context that wassaved at some point previously.

In transferring control from the Code Cache the system does a contextswitch consisting of the following:

-   -   Save application context (580). [Consisting of the registers,        condition codes etc.]    -   Restore Monitor Processor context (581).    -   Turn off write-protection for the Code Cache and for the data        structures associated with the Monitor and Enforcement        Processors (582). There are many different methods of        implementation, mainly using the various protection mechanisms        provided by the hardware.

In transferring control from the Enforcement or Monitor Processors tothe Code Cache the system does a context switch consisting of thefollowing:

-   -   Save Monitor Processor context (583).    -   Turn on write-protection for the Code Cache and for the data        structures associated with the Monitor and Enforcement        Processors (584).    -   Restore application context (585).

Execution Model Enforcement

The system can also use static and dynamic analyses to automaticallybuild a custom security policy for a target program that specifies theprogram's execution model. This process requires no user interaction,but is able to build a strict enough policy to prevent all deviationsfrom the program's control flow graph and nearly all violations of thecalling convention, greatly reducing the possibility of an unintendedprogram action.

The execution model of a program includes several components. At thelowest level, the Application Binary Interface (ABI) specifies theregister usage and calling conventions of the underlying architecture,along with the operating system interface mechanism. Higher-levelconventions come from the source language of the program in the form ofruntime data structure usage and expected interaction with the operatingsystem and with system libraries. Finally, the program itself isintended by the programmer to perform a limited set of actions.

Even the lowest level, the ABI, is not efficiently enforceable. Theunderlying hardware has no support for ensuring that calls and returnsmatch, and it is prohibitively expensive to implement this in software.For this reason, the execution model is a convention rather than astrict set of rules. However, most security exploits come fromviolations of the execution model. The most prevalent attacks todayinvolve overwriting a stored program address with a pointer to injectmalicious code. The transfer of control to that code is not allowedunder the program's execution model. Enforcing the model would thwartmany security attacks.

FIG. 25: Call Matching

FIG. 25 includes three flow charts (25A, 25B and 25C) that describe howto keep a hash value in order to verify that the stack discipline hasnot been violated. In order to implement this restricted controltransfer rule, the call and return instructions need to be sandboxed tocarry out the actions described in these flow charts. The first flowchart describes how to initialize the data structures.

A number of attacks have been constructed out of various function callsby improperly manipulating return addresses. Such attacks violate thestandard matching of calls and returns. FIG. 25's call matching approachuses a simple symmetric encryption scheme, where an input value isencrypted at a call using a call-site-specific key, while that same keyis used to decrypt the encrypted value at a return. If the call andreturn match up properly, the input value comes out unchangedafterwards.

At the start of a program the system (710) calculates a random key foreach call site in the program. It also derives a random hash value thatis saved for later use (711). This hash value will be invariant if allchecked calls and returns match up properly. Before a call site, thesystem determines if checking is enabled for that site (712). If so, thesystem stores the previously saved hash value in a call-site specificlocation (713) and optionally protects it. In any case, if checking isenabled for this site, at (714), the system encodes the hash value usingthe call-site-specific key and stores the resulting value in thecall-specific location. After a call instruction, at (715) it decodesthe saved value using the call-specific key and puts it back in thesite-specific location. If checking is enabled at this site (716), thesystem compares the current hash value with the stored one (717). Ifthey are the same, the program has returned to the same function thatexecuted the previous call. Note that the final check can be carried outat any time, such as just before security sensitive system calls.

FIG. 26: Stack-Based Return Protection

FIG. 26 includes three flow charts that describe how to enforce thestack discipline using a separate shadow stack. In order to implementthis restricted control transfer rule, the call and return instructionsneed to be sandboxed to carry out the actions described in these flowcharts. The first flow chart describes how to initialize the datastructures.

Function calls follow a fixed protocol where a return value, i.e., theaddress following the call, is saved on the runtime stack so that whenthe function ends it can get back to where it came from. This istypically done by executing a return instruction that jumps to thereturn address saved on the runtime stack. Because of its location nearuser data, this saved return value on the stack is vulnerable toimproper modification. One way to prevent this is to additionally savethe return value in a shadow stack in a separate location away from anyuser data. The two values from both stacks should never be different.

At the start of a program the system (722) allocates memory for a shadowstack and then initializes a stack pointer for it (723), which points tothe first available location in the shadow stack. Before a callinstruction, the system unprotects the shadow stack, if needed (720),copies the return address to the shadow stack (724), increments theshadow stack pointer (725) and optionally re-protects the shadow stack(721). Before a return instruction, the system unprotects the shadowstack, if necessary (720), and checks if the top of shadow stack addressmatches the return destination address (726). If not, there is asecurity violation. Otherwise, the system decrements the shadow stackpointer (727) and optionally re-protects the shadow stack (721).

FIG. 27: Return Protection Using XMM Registers as a Buffer

FIG. 27 includes flow charts that describe how to enforce the stackdiscipline using a separate shadow stack that is optimized using the XMMregisters. The XMM registers are used as a buffer to store the topelements of the stack. This speeds up the operations on the shadow stackwithout compromising the security of the stack.

The high-level idea here is to use hardware registers such as the XMMregisters as the top of a stack that is used to save return values forthe purpose of detecting stack tampering, as in FIG. 26 above. Use ofthe XMM registers provides more efficient stack operations, avoidingfrequent reads and writes to memory and also taking advantage ofparallelism within the processor. One embodiment of the systemimplements a call stack using the SIMD registers of the Pentium 4. ThePentium 4 SSE and SSE2 extensions add eight 128-bit registers (the XMMregisters) that can hold single-precision, double-precision, or integralvalues. For a program that does not make use of these registers, theycan be stolen and used as a call stack. The SSE2 instruction setincludes instructions for transferring a 16-bit value into or out of oneof the eight 16-bit slots in each XMM register. Unfortunately, storing a32-bit value is much less efficient. However, just the lower 16 bits ofreturn addresses are sufficient to distinguish almost all validaddresses. For a number of applications there are no return addressesthat share their least significant 16 bits. Using just the lower 16bits, then, does not sacrifice much security. It also allows twice asmany return addresses to be stored in the register stack. The systemfurther enhances this approach by hashing the 32-bit value andtruncating the hash to 16 bits, called a reduced bit hash, to obtain thevalue to be placed in the XMM stack. The final 16-bit slot is used tostore the counter indicating the location of the top-of-the-stack In theXMM registers, leaving room for 63 return address entries. Note that anyother set of available registers for a particular processor model can bechosen. Furthermore, some components of FIG. 27 can be implemented inhardware.

On a call, the return address is stored in the XMM slot pointed at bythe counter. When the end is reached (the 63^(rd) slot), the oldest 32values are copied to a continuation stack in memory which is thenprotected and the rest of the slots are shifted down by 32 slots. Whenthe index reaches 0, the most recent stored values are swapped back intothe first 32 register slots and the index updated. Only copying half ofthe stack avoids thrashing due to a frequent series of small call depthchanges. Expensive memory protection is only required on every calldepth change of 32.

Please refer to FIG. 27. At the start of a program the systeminitializes the index counter in the XMM registers (732), initializes acontinuation stack for saving the overflowed XMM registers in memory(733), initializes the stack pointer to the continuation stack in memory(734) and finally protects the continuation stack in memory (735).

Before a call instruction, the system increments the counter (736) andif the counter is above a threshold (737), the XMM stack is full. Inorder to make room in the XMM stack by flushing half of it to thein-memory stack, the system does the following:

-   -   Unprotect the continuation stack in memory, using an unprotect        system call to change the permissions of the page containing the        stack (738).    -   Copy the bottom of the XMM stack to the continuation stack,        which is done by a series of store operations of the individual        XMM register values into the memory locations of the        continuation stack (739).    -   Shift the remaining values in the top of the XMM stack to the        bottom of the XMM stack (740).    -   Update the index counter to indicate that the new top-of-the        stack is now at the midpoint (741).    -   Protect the continuation stack in memory (742).        In either case, the system creates a reduced-bit hash of the        destination address, i.e. the address following the call (743),        and copies the hash to the XMM register pointed to by the        counter (744).

FIG. 28: XMM Return Protection with Buffer, Continued

FIG. 28 is a flow chart that describes the sandboxing operations of thereturn instruction, required to implement the return address protectiondescribed in FIG. 27. This figure continues XMM return protection with abuffer by describing the steps taken to validate the stack discipline ata return instruction.

Before a return instruction, the system creates a reduced-bit hash ofthe destination address (750), as described above, gets the value at thetop of the XMM stack pointed at by the index register (751) and thecompares the two (752). If they are not the same, there is a securityviolation. Getting the value at the top of the XMM stack (751) is doneby using the value in the index as an offset into the XMM registerswhich is done by using a switch statement to handle the variableregister addressing.

If they match, the system decrements the counter (753). If the XMM stackis empty, the counter will be zero (754). The system then needs topopulate the XMM stack by getting values from the continuation stack inmemory by doing the following:

-   -   Unprotect the continuation stack in memory, by changing the        permissions on the containing page (755).    -   Copy the top of the continuation stack to the bottom half of the        XMM registers and update the continuation stack pointer (756)    -   Update the index counter (757).    -   Protect the continuation stack in memory (758).

FIG. 29: Return Protection Using XMM Registers as a Shift Register

FIG. 29 includes flow charts that describe how to enforce the stackdiscipline using a separate continuation stack that is optimized usingthe XMM registers. The XMM registers are used as a shift register tostore the top elements of the stack. The main difference between theembodiment described in FIGS. 27 and 28 and this embodiment is that herethe XMM registers are used as a shift register. Thus, thetop-of-the-stack is always at slot 0 in the XMM registers. Thissimplifies the code needed to push and pop values into the XMM stack.The final 16-bit slot is used to store the call depth, leaving room for63 return address entries.

On a call, the slots are shifted over and the return address is storedin the first slot. When the call depth exceeds 63, the oldest 32 valuesare copied to a continuation stack in memory which is then protected.When the call depth reaches 0, the most recent stored values are swappedback into the first 32 register slots. Only copying half of the stackavoids thrashing due to a frequent series of small call depth changes.Expensive memory protection is only required on every call depth changeof 32.

At the start of a program, the system initializes the call-depth counterin the XMM registers (760), initializes a continuation stack for savingthe overflowed XMM registers in memory (761), initializes a stackpointer to the continuation stack (762) and finally protects thecontinuation stack in memory (763). Before a call instruction, thesystem increments the XMM call-depth counter (770) and if the counter isabove a threshold (771), indicating that the XMM stack is full, thesystem does the following:

-   -   Unprotect the continuation stack in memory, using an unprotect        system call to change the permissions of the page containing the        stack (772).    -   Copy the bottom of the XMM stack to the continuation stack,        which is done by a series of store operations of the individual        XMM register values into the memory locations of the stack        (773).    -   Update the call-depth counter to indicate that only half of the        XMM registers have data (774).    -   Protect the continuation stack in memory (775).

In either case, the system creates a reduced-bit hash of the destinationaddress, i.e., the address following the call (776), shifts all thevalues in the XMM registers to create an empty slot (777), copies thehash to the first slot in the XMM registers (778) and updates the depthcounter (779).

FIG. 30: XMM Return Protection with Shift Register, Continued

FIG. 30 is a flow chart that describes the steps taken to validate thestack discipline at a return instruction in order to enforce the returnprotection described in FIG. 29.

Before a return instruction, the system creates a reduced-bit hash ofthe destination address (780), as described above, gets the value at thetop of the XMM stack (781) and then compares the two (782). If they arenot the same, there is a security violation. If they match, the systemdecrements the call depth counter (783) and if it is zero (784),indicating that the XMM stack is empty, does the following:

-   -   Unprotect the continuation stack in memory, by changing the        permissions on the containing page (785).    -   Copy the top of stack from the continuation stack to fill half        of the XMM registers, and update the continuation stack pointer        (786).    -   Protect the continuation stack in memory (787).    -   Update the XMM call-depth counter (788).

FIG. 31: Function Analysis

FIG. 31 is a flow chart that describes the steps taken by the analysisprocessor to create a simple application-specific policy. The degree offreedom of an attacker is given by the size of the set of allowed valuesfor an attacked stored program address. Ideally, these sets should besingletons, because in a real program execution at any point there isonly one valid value (in the absence of race conditions). Therefore, weaim to minimize the size of the sets and convert them to singletons whenpossible. Our first aim is to determine the points-to sets for functionpointers by using an accurate static analysis. We use a flow-insensitive(to allow for concurrency) and context-insensitive analysis to gatherthe sets of valid targets for indirect calls. Using that information weconstruct the complete call graph for the program. Targets of returninstructions are then computed from the graph, since the instructionsafter caller sites of a function constitute the only valid targets forits exit point.

Context-insensitive policies make an attacker's life much moredifficult, narrowing potential attack targets from any instruction inthe program to a small handful. The program's control flow graph andcall graph can be enforced using only context-insensitive policies, assuch graphs are themselves context-insensitive. However, the executionmodel is more than the control flow graph. For one thing, the modelincludes the calling convention, which restricts each return to haveonly one target (the return site of the caller), depending on thecontext.

Given the limit on execution models to those that disallowself-modifying code, direct control transfers will always perform as theprogram intends, as they are part of the code itself and cannot bemodified by an attacker.

Indirect calls, indirect jumps, and returns obtain their targets fromdata, which can be modified by an attacker. Program shepherding allowsarbitrary restrictions to be placed on control transfers in an efficientmanner. Enforcing the execution model involves allowing each branch tojump only to a specified set of targets.

Static analyses produce context-insensitive policies, which can beeasily enforced with minimal overhead. This is becausecontext-insensitive policies are always valid after initialverification, and thus can be cached and cheaply evaluated with minimalexecution overhead. Policies that only examine the target of a controlflow transition are the cheapest, as a shared hash table per indirecttransfer type can be used to look up the target for validation. Policiesthat need to examine both the source and the target of a transition canbe made as efficient as only checking the target by using a separatehash table for each source location. The space drawback of this schemeis minor as equivalent target sets can be shared, and furthermore, thehash tables can be precomputed to be kept quite small without increasein access time.

Please refer to FIG. 31. Here the system analyzes the entire applicationvia either source or binary (810) to identify all the functions whoseaddress is taken into a variable (811). The variable referred to in(811) is a function pointer because it holds function addresses. The setof functions whose address is taken into a particular variable is termedas the “points to set” for the function pointer. Such analysis iswell-known in the art. In this case the approach taken is even simplersince all these function addresses are consolidated into a single list.Then those function addresses on the list are the only ones that can belegally called. The system copies the list of these legal functionaddresses to the policy database (812) and creates anapplication-specific policy where the only allowed indirect functioncalls are to the functions in this list (813).

FIG. 32: Branch Analysis

FIG. 32 is a flow chart that describes the steps taken by the analysisprocessor to create a more fine-grained application-specific policy thanthat described in FIG. 31.

First, the system performs Pointer Alias Analysis of the entireapplication (820). This is also well-known in the art [L. O. Andersen,“Program Analysis and Specialization for the C Programming Language”,PhD thesis, DIKU, University of Copenhagen, May 1994, DIKU report94/19]. It allows the system to get an accurate list of which functionsa particular function pointer can reference. Aliasing is a well-knownconcept that arises because different pointers can refer to the samememory locations. For each indirect branch site, the system calculatesthe points-to set (821). The alias analysis provides a safedetermination, that is as accurate as possible, of the points-to set foreach call site. The system records the points-to sets of each indirectbranch site to the policy database (822) and creates anapplication-specific policy where each indirect branch can only transfercontrol to destinations in its points-to set (823).

FIG. 33: Branch Profiling

FIG. 33 is a flow chart that describes how to use profile information inorder to create an application-specific security policy. An easy way toobtain the target sets for a flow-insensitive, context-insensitivevalidation in the program shepherding system is to first run it in“learning” mode to collect indirect transition information, and then usethe results of such learning runs and allow only those transitions.However, it is prone to false positives unless profiling runs have veryhigh code coverage.

The system analyzes the application to find those control transferswhere the destination is not known at compile time (830). It theninstruments those control transfers to record the destinations atruntime (831). The system runs the program and gathers the data onactual control transfer targets (832). It analyzes the data to produce arestricted set of control transfers to match the actual controltransfers (833) and creates an application-specific policy where eachindirect branch can only transfer control to destinations that wereeither extracted from analysis or learning (834).

The foregoing detailed description of the invention has been presentedfor purposes of illustration and description. It is not intended to beexhaustive or to limit the invention to the precise form disclosed. Manymodifications and variations are possible in light of the aboveteaching. The described embodiments were chosen in order to best explainthe principles of the invention and its practical application to therebyenable others skilled in the art to best utilize the invention invarious embodiments and with various modifications as are suited to theparticular use contemplated. It is intended that the scope of theinvention be defined by the claims appended hereto.

1. A method for securing a computing system having a processor, themethod comprising: analyzing control transfers of a program as theprogram executes on said computing system, said program comprisinginstructions, each of the instructions being machine code of theprocessor, and said control transfers each caused by execution ofcorresponding control transfer instructions, the control transferinstructions causing a break in sequential flow of program execution,thereby determining a next instruction of the program to execute, saidanalyzing of the control transfers being performed prior to theexecution of the control transfer instructions; and ensuring that eachsaid control transfer complies with a security policy, said securitypolicy comprising a set of rules against which each of the controltransfers is separately evaluated during the analyzing, the ensuringcomprising announcing or handling a security violation when the controltransfer does not comply with the security policy.
 2. A method accordingto claim 1, wherein: said step of ensuring includes restrictingexecution privileges based on code origins by checking an origin of codeof said program against said security policy to determine if said codeshould be given execute privileges, said checking of said origincomprises determining whether said code is: a) from an original image ondisk and unmodified, b) dynamically generated but unmodified sincegeneration or c) modified.
 3. A method according to claim 1, wherein:the control transfers are of different types, and said security policyincludes a set of rules that are separately definable for each type ofcontrol transfer; and the different types include at least: direct call,indirect call, return, conditional branch, direct jump, indirect jumpand interrupt.
 4. A method according to claim 1, wherein: said step ofensuring includes restricting control transfers based on instructiontype.
 5. A method according to claim 1, wherein: said step of ensuringincludes restricting at least one of said control transfers based on asource of said at least one of said control transfer instructions, saidrestricting implements a restriction which is specific to a type of saidat least one of said control transfers.
 6. A method according to claim1, wherein: said step of ensuring includes restricting at least one ofsaid control transfers based on a target of said at least one of saidcontrol transfers, said restricting implements a restriction which isspecific to a type of said at least one of said control transfers.
 7. Amethod according to claim 1, wherein said step of ensuring includesrequiring a pre-defined prologue before execution of a sequence of atleast one of said instructions of the program, and/or a pre-definedepilogue after execution of said sequence.
 8. A method according toclaim 1, wherein: said step of ensuring includes restricting executionprivileges based on code origins, preventing bypass of sandboxing checksplaced around a program operation and restricting the control transfersbased on at least any one of source, destination or instruction class.9. A method according to claim 1, wherein said step of ensuringincludes: determining whether code of said program at a target of saidcontrol transfer has been modified; and preventing execution of saidcode of said program which has been determined to be modified.
 10. Amethod according to claim 1, wherein: said step of ensuring includesensuring that shared library code is entered only through declared entrypoints.
 11. A method according to claim 1, wherein: said step ofensuring includes verifying all branch instructions of said programcomply with the security policy.
 12. A method according to claim 1,wherein: said control transfer instructions include a returninstruction; and said step of ensuring includes requiring that adestination of said return instruction is immediately preceded by adirect or indirect call instruction.
 13. A method according to claim 1,wherein: at least one of said instructions of said program is from acorresponding code page of an original application or library image ondisk; and said step of ensuring includes determining whether saidcorresponding code page has been modified during execution of theprogram and allowing execution of said at least one of said instructionswhen said said corresponding code page has not been modified duringexecution of the program.
 14. A method according to claim 1, wherein:said step of ensuring includes verifying targets of calls against apredefined list.
 15. A method for securing a computing system having aprocessor, the method comprising: accessing a set of rules fortransferring control of a program on said computing system; analyzingcontrol transfers of said program as the program executes on saidcomputing system, said program comprising instructions, each of theinstructions being a member of an instruction set of the processor, andsaid control transfers each caused by execution of corresponding controltransfer instructions, the transfer instruction causing a break insequential flow of program execution, thereby determining a nextinstruction of the program to execute, said analyzing of the controltransfers being performed prior to the execution of the control transferinstruction; and enforcing said rules for said control transfers forsaid program, said enforcing comprising: evaluating, during theanalyzing, each of the control transfers against the rules; andannouncing or handling a security violation instead of a target of thecontrol transfer instruction when the control transfer instruction doesnot comply with the rules.
 16. A method according to claim 15, wherein:said step of enforcing includes restricting execution privileges basedon code origins, including determining whether code of said program is:a) from an original image on disk and unmodified, b) dynamicallygenerated but unmodified since generation or c) modified.
 17. A methodaccording to claim 15, wherein said step of enforcing includesrestricting the control transfers based on a source of the controltransfer instructions.
 18. A method according to claim 15, wherein saidstep of enforcing includes restricting the control transfers based onthe target of the control transfer instructions.
 19. A method accordingto claim 15, wherein said step of enforcing includes requiring apre-defined prologue before execution of a sequence of at least one ofsaid instructions of the program and/or a pre-defined epilogue afterexecution of said sequence.
 20. A method according to claim 15, wherein:said step of enforcing includes restricting execution privileges basedon code origins, preventing bypass of sandboxing checks placed around aprogram operation and restricting the control transfers based on atleast any one of source, destination or instruction class.
 21. One ormore processor readable storage devices having processor readable codeembodied on said storage devices, said processor readable code forprogramming one or more processors to perform a method comprising:analyzing control transfers of a program as said program executes on acomputing system, said program comprising instructions, each instructionis native code of the one or more processors, said control transferseach being caused by execution of corresponding control transferinstructions causing a break in sequential flow of program execution,thereby determining a next instruction of the program to execute, saidanalyzing of the control transfers being performed prior to theexecution of the control transfer instructions; and ensuring that eachsaid control transfer complies with a security policy, said securitypolicy comprising a set of rules against which each of the controltransfers is separately evaluated as part of the analyzing, the ensuringcomprising announcing or handling a security violation when the controltransfer instruction does not comply with the security policy.
 22. Oneor more processor readable storage devices according to claim 21,wherein: said enforcing of said security policy includes restrictingexecution privileges based on code origins, including determiningwhether code of said program is: a) from an original image on disk andunmodified, b) dynamically generated but unmodified since generation orc) modified.
 23. One or more processor readable storage devicesaccording to claim 21, wherein said step of ensuring includesrestricting at least one of said control transfer instructions based oninstruction class.
 24. One or more processor readable storage devicesaccording to claim 21, wherein: said enforcing of said security policyincludes restricting control transfers based on instruction sourceand/or target.
 25. One or more processor readable storage devicesaccording to claim 21, wherein: the control transfers are of differenttypes, including types of direct call, indirect call, return,conditional branch, direct jump, indirect jump and interrupt, and saidsecurity policy includes different restrictions for the different typesof control transfers.
 26. One or more processor readable storage devicesaccording to claim 21, wherein said step of ensuring includes requiringa pre-defined prologue before execution of a sequence of at least one ofsaid instructions of the program and/or a pre-defined epilogue afterexecution of said sequence.
 27. One or more processor readable storagedevices according to claim 21, wherein: said step of ensuring includesrestricting execution privileges based on code origins, preventingbypass of sandboxing checks placed around a program operation andrestricting the control transfers based on at least any one of source,destination or instruction class.
 28. A method according to claim 1,wherein: said step of ensuring includes ensuring that all controltransfers for said program comply with said security policy.
 29. Amethod according to claim 1, wherein said step of ensuring determineswhether instructions of said program at a target of the controltransfers are from code pages which are unmodified during execution ofsaid program.
 30. A method according to claim 29, wherein said codepages are determined to be unmodified by maintaining a list ofunmodified code pages.
 31. A method according to claim 1, wherein saidstep of ensuring further comprises determining whether said instructionsat a target of the control transfers were present when said program isoriginally loaded, and have not been modified after being loaded.
 32. Amethod according to claim 31, wherein said instructions of said programare determined to be unmodified after being loaded by maintaining a listof modified code pages.
 33. A method according to claim 1, wherein saidstep of ensuring includes determining whether a matching rule of saidsecurity policy is found for a source address, destination address andinstruction type associated with at least one of said control transfers,and applying the matching rule to the associated control transfer.
 34. Amethod according to claim 33, wherein said security policy includesdifferent rules for different control transfer types, including types ofat least: direct call, indirect call, return, conditional branch, directjump and interrupt.
 35. A method according to claim 15, wherein: saidprogram comprises modules and said rules restrict intra-module controltransfers.
 36. A method according to claim 15, wherein: said rules allowa return instruction of said program to execute when a destination ofsaid return instruction is immediately preceded by a direct or indirectcall instruction that was previously executed.
 37. A method according toclaim 15, wherein: said rules include different rules for handling acontrol transfer which is conditional, a control transfer which isunconditional and a control transfer which is indirect.
 38. A methodaccording to claim 15, wherein: at least one of said control transferscomprises a kernel mediated control transfer; and said step of enforcingincludes ensuring that said kernel mediated control transfer complieswith said rules.
 39. A method according to claim 15, wherein: said rulesinclude different rules for handling a control transfer which is due toan exception and a control transfer which is due to an interrupt.
 40. Amethod according to claim 15, wherein: said step of enforcing includesrestricting a plurality of said control transfers, including a controltransfer which provides a direct call and a control transfer whichprovides an indirect call, said restricting implements a directcall-specific restriction for said control transfer which provides saiddirect call, and an indirect call-specific restriction for said controltransfer which provides said indirect call.
 41. A method according toclaim 15, further comprising: said step of enforcing includesrestricting a plurality of said control transfers, including a controltransfer which provides a jump and a control transfer which provides areturn, said restricting implements a jump-specific restriction for saidcontrol transfer which provides said jump, and a return-specificrestriction for said control transfer which provides said return.
 42. Amethod according to claim 1, wherein: each instruction is a machinelanguage primitive which is directly executed on the processor.
 43. Amethod according to claim 1, wherein: the program comprises modules, oneof the control transfers is a direct or indirect jump from a source to adestination, and the plurality of rules includes a rule for the director indirect jump which comprises determining whether the source and thedestination of the direct or indirect jump are within the same module ofthe program.
 44. A method according to claim 1, wherein: the programcomprises modules, each module comprises a group of functions, one ofthe control transfers is a direct jump to a target, and the plurality ofrules includes a rule for the direct jump which comprises determiningwhether the target of the direct jump is within the direct jump's ownfunction.
 45. A method according to claim 1, wherein: one of the controltransfers is a return to a destination, and the plurality of rulesincludes a rule for the return which comprises determining whether thedestination is present in a valid return address list.
 46. A methodaccording to claim 1, wherein: one of the control transfers is a call,and the plurality of rules includes a rule for the call which comprisesdetermining whether a destination of the call is a call entry point. 47.A method according to claim 1, wherein: the program comprises modules,one of the control transfers is a call to a destination, and theplurality of rules includes a rule for the call which comprisesdetermining whether the call and the destination are both within thesame module of the program.
 48. A method according to claim 1, wherein:one of the control transfers is a call to a callee, the call iscontained in a module of the program, and the plurality of rulesincludes a rule for the call which comprises determining whether thecallee is imported by the module that contains the call instruction. 49.A method according to claim 1, wherein: one of the control transfers isa call to a callee, the callee is contained in a module of the program,and the plurality of rules includes a rule for the call which comprisesdetermining whether the callee is exported by its containing module. 50.A method according to claim 1, wherein: one of the control transfers isa call from at least one source, and the plurality of rules includes arule for the call which comprises determining whether the source of thecall is in a library module.
 51. A method according to claim 1, wherein:the program comprises modules, one of the control transfers is a jumpfrom a source to a destination, and the plurality of rules includes arule for the jump which comprises determining whether the source and thedestination of the jump are within the same module of the program; oneof the control transfers is a return to a destination, and the pluralityof rules includes a rule for the return which comprises determiningwhether the destination is present in a valid return address list; andone of the control transfers is a call, and the plurality of rulesincludes a rule for the call which comprises determining whether adestination of the call is a call entry point.
 52. A method according toclaim 1, wherein: the control transfers are of different types, and saidset of rules is separately definable for each type of control transfer,the different types include: exceptions and kernel mediated controltransfers.
 53. A method according to claim 15, wherein: the controltransfers are of different types, including types of direct call,indirect call, return, conditional branch, direct jump, indirect jumpand interrupt, and said set of rules is separately definable for eachtype of control transfer.